# -*- coding: cp1252 -*-
import wx
import wx.grid
import base64
from wx.lib.masked import *
#Bibloteca para a conexao com o banco de dados
import adodbapi
import sys
#!/usr/bin/python


sys.path[0]
cont = sys.path[0].find('pygb-gerenciador-de-biblioteca') + 30
sys.path[0] = sys.path[0]+"/banco"
from bd import *
sys.path[0] = sys.path[0][:cont]

from admin import *

#Painel(Frame) pricipal do sistema.

class AdminSenha(wx.Frame):
    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, 'Administrador Senha',size=(300, 200), style= wx.CAPTION)

        #Painel Cliente, onde agrego os outros componentes, e ele e agregado ao frame
        self.adminsenha = wx.Panel(self)

        fontexit = wx.Font(12,wx.DEFAULT, wx.NORMAL, wx.NORMAL)
        lyricas4 =  wx.StaticText(self.adminsenha,-1,' Administrador ', (90,20), (140,140), style = wx.ALIGN_CENTER)
        lyricas4.SetFont(fontexit)


        lyricas5 =  wx.StaticText(self.adminsenha,-1,'Senha: ', (30,60), (140,140), style = wx.ALIGN_CENTER)
        lyricas5.SetFont(fontexit)

        self.senha = wx.TextCtrl(self.adminsenha, -1,pos=(100,60),size=(150,20) , style = wx.TE_PASSWORD)


        self.ok =  wx.Button(self.adminsenha,-1, 'Ok', pos =(35,100), size=(100,40))
        self.ok.Bind(wx.EVT_BUTTON, self._entrar)

        self.cancel =  wx.Button(self.adminsenha,-1, 'Cancelar', pos =(155,100), size=(100,40))
        self.cancel.Bind(wx.EVT_BUTTON , self._voltar)
            #Butao Exit

        #Estatic Text do Butao Exit



        #voltar
        self.buttonback = wx.BitmapButton (self.adminsenha, id=-1,  bitmap = self.imagembt("back.png"), pos = (23,510), size = (48,48))
        voltar = wx.StaticText(self.adminsenha,-1,'Voltar', (34,558))
        self.buttonback.Bind(wx.EVT_BUTTON, self._voltar)




    def imagembt(self,imageFile):
        imageFile = 'img/'+imageFile
        imagem = wx.Image(imageFile, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
        return imagem

    def _voltar(self, event):
        self.Destroy()


    def _entrar(self, event):
        self.senhaa = self.senha.GetValue()
        self.senhaa= int(self.senhaa)
        result = bancoadmin().Getsenha()
        for i in result:
       	    self.senhabanco =  i[1]

        print self.senhabanco

        if self.senhaa == self.senhabanco :
                admin = Admin(parent=None, id=-1)
                admin.Show()
                self.Destroy()
        else:
            dlg = wx.MessageDialog(self, 'Senha incorreta', 'Erro!', wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()


